package com.minelx.hellopandas.core;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.util.List;
import java.util.Objects;

public class DataFrame {

	private final PandasMethodProvider pandasMethodProvider;

	private final DataFrameDescription self;

	DataFrame(PandasMethodProvider pandasMethodProvider, DataFrameDescription self) {
		this.pandasMethodProvider = pandasMethodProvider;
		this.self = self;
	}

	public void filter(JSONObject conditionAsJSON) {
		pandasMethodProvider.filter(self, conditionAsJSON, self.uri());
	}

	public void retains(List<String> retainedColumns) {
		pandasMethodProvider.retains(self, retainedColumns, self.uri());
	}

	public void dropDuplicates() {
		pandasMethodProvider.dropDuplicates(self, self.uri());
	}

	public void dropNaN(List<String> columns, String how) {
		pandasMethodProvider.dropNaN(self, columns, how, self.uri());
	}

	public void drop(List<String> droppedItems) {
		pandasMethodProvider.drop(self, droppedItems, 1, self.uri());
	}

	public DataFrame aggregate(List<String> groupBy, JSONArray specs) {
		return new DataFrame(
				// FIXME test coverage...    aggregate may change dtype of columns, should swap dataframe description after execution
				pandasMethodProvider,
				pandasMethodProvider.aggregate(self, groupBy, specs, self.uri()));
	}

	public void merge(DataFrame another, List<String> on, String how) {
		pandasMethodProvider.merge(self, another.self, on, on, how, self.uri());
	}

	public DataFrameDescription description() {
		return self;
	}

	@Override
	public boolean equals(Object o) {
		if (this == o) return true;
		if (o == null || getClass() != o.getClass()) return false;
		DataFrame that = (DataFrame) o;
		return self.equals(that.self);
	}

	@Override
	public int hashCode() {
		return Objects.hash(self);
	}
}
